/*
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.odichy.andfml.domain;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * AndFML, an FMyLife.com client on Google Android platform.
 *
 * @author Odin Liu<odinushuaia@gmail.com>
 *
 * @version 1.0.0
 */
public class FMLList {
	private List<FMLItem> itemList;
	private int totalPages;
	private int code;
	private String pubdate;
	private List<String> errors;
	public FMLList() {
		itemList = new ArrayList<FMLItem>();
		errors = new ArrayList<String>();
	}
	public boolean addFMLItem(FMLItem item) {
		return itemList.add(item);
	}
	public boolean addError(String error) {
		return errors.add(error);
	}
	public int getTotalPages() {
		return totalPages;
	}
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}
	public int getCode() {
		return code;
	}
	public void setCode(int code) {
		this.code = code;
	}
	public String getPubdate() {
		return pubdate;
	}
	public void setPubdate(String pubdate) {
		this.pubdate = pubdate;
	}
	public List<FMLItem> getItemList() {
		return itemList;
	}
	public List<String> getErrors() {
		return errors;
	}
	public List<Map<String, String>> getFMLListForListView() {
		List<Map<String, String>> data = new ArrayList<Map<String, String>>();
		Map<String, String> map;
		for(FMLItem item: itemList) {
			map = new HashMap<String, String>();
			map.put(FMLItem.ID, String.valueOf(item.getId()));
			map.put(FMLItem.TEXT, item.getDecodeText());
			map.put(FMLItem.AGREE, String.valueOf(item.getAgree()));
			map.put(FMLItem.DESERVED, String.valueOf(item.getDeserved()));
			map.put(FMLItem.COMMENTS, String.valueOf(item.getComments()));
			data.add(map);
		}
		return data;
	}
	public FMLItem getFML(int position) {
		return itemList.get(position);
	}
}
